/*
	fastaddstation.cpp

	Copyright (c) 2009 by Lms <lms.cze7@gmail.com>

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
*/

#include "fastaddstation.h"
#include "ui_fastaddstation.h"

FastAddStation::FastAddStation(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::FastAddStation)
{
    m_ui->setupUi(this);

	connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}

FastAddStation::~FastAddStation()
{
    delete m_ui;
}

void FastAddStation::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void FastAddStation::showEvent()
{

}

void FastAddStation::accept()
{
	QSqlQuery query(sqldb.db);
	query.prepare("INSERT INTO Stations ([group], [name]) VALUES ('', ?)");
	query.addBindValue(m_ui->lineEditName->text());
	if (!query.exec()){
		qDebug()<<"[FMtune]"<<"insert error, table Stations"<<"AddFeed::accept()";
	}

	QSqlQuery query2(sqldb.db);
	query2.prepare("INSERT INTO Streams ([stationid], [format], [url]) VALUES (?, ?, ?)");
	query2.addBindValue( query.lastInsertId() );
	query2.addBindValue(tr("stream"));
	query2.addBindValue(m_ui->lineEditURL->text());
	if (!query2.exec()){
		qDebug()<<"[FMtune]"<<"insert error, table Streams"<<"AddFeed::accept()";
	}

	done(0);
}

void FastAddStation::reject()
{
	done(0);
}
